package git

import (
	"github.com/chmodke/gitmm/config"
	"github.com/chmodke/gitmm/log"
)
import "github.com/chmodke/gitmm/util"

// RemoteShow show remote address
func RemoteShow(workDir string, repo config.Repo) bool {
	builder := &util.CmdBuilder{}
	builder.Add("git").Add("remote -v")
	out, ret := util.GetOut(util.Execute(repo.LocalPath(workDir), builder.Build()))
	log.Consoleln(out)

	return ret
}

// RemoteAdd add remote address
func RemoteAdd(workDir string, repo config.Repo, remote config.Remote) bool {
	builder := &util.CmdBuilder{}
	builder.Add("git").Add("remote").Add("add").Add(remote.Name).Add(repo.RemotePath(remote))
	_, ret := util.GetOut(util.Execute(repo.LocalPath(workDir), builder.Build()))
	RemoteShow(workDir, repo)

	return ret
}

// RemoteRemove add remote address
func RemoteRemove(workDir string, repo config.Repo, remote string) bool {
	builder := &util.CmdBuilder{}
	builder.Add("git").Add("remote").Add("remove").Add(remote)
	_, ret := util.GetOut(util.Execute(repo.LocalPath(workDir), builder.Build()))
	RemoteShow(workDir, repo)

	return ret
}
